$(function () {
    $("#jqGrid").jqGrid({
        url: '../sys/execl/list',
        datatype: "json",
        colModel: [
            { label: '订单编号', name: 'ordercode', width: 60 },
			{ label: '姓名', name: 'name', width: 60 },
			{ label: '6g', name: 'g56', width: 60 },
			{ label: '200g', name: 'g200', width: 60 },
			{ label: '300g', name: 'g300', width: 60 },
			{ label: '500g', name: 'g500', width: 60 },
			{ label: '罐500g', name: 'u500', width: 60 },
			{ label: '压片糖', name: 'g6', width: 60 },
			{ label: '销售总额', name: 'money', width: 60 },
			{ label: '重量(kg)', name: 'weight', width: 60 },
			{ label: '快递方式', name: 'express', width: 60 },
			{ label: '运费(元)', name: 'postage', width: 60 },
			{ label: '支付时间', name: 'payDate', width: 60 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			key: null
		},
		showList: true,
		title: null,
		config: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		output: function () {
			var exportFileVal = $("#exportFile").val();
//			if (exportFileVal == "" || exportFileVal == null) {
//				alert("导出失败，请输入参数");
//				return;
//			}
        	window.location.href = "../sys/execl/exportXls.do?fileName="+exportFileVal;
        },
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.config = {};
		},
		update: function () {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
			$.get("../sys/config/info/"+id, function(r){
                vm.showList = false;
                vm.title = "修改";
                vm.config = r.config;
            });
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../sys/config/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								vm.reload();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		dele: function (event) {
        		$.ajax({
        			type: "POST",
        			url: "../sys/execl/dele",
        			success: function(r){
        			if(r.code == 0){
        				alert('操作成功', function(index){
        					vm.reload();
        					});
        				}else{
        					alert(r.msg);
        					}
        				}
        		});
        },
		saveOrUpdate: function (event) {
			var url = vm.config.id == null ? "../sys/config/save" : "../sys/config/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.config),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'key': vm.q.key},
                page:page
            }).trigger("reloadGrid");
		}
	}
});